package com.test.ddaidai;

import com.test.ddaidai_android.activity.R;

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;


public class BaseActivity extends FragmentActivity {

	private TextView mTextTitle;
	
	public void setTitle(String title) {
		if (mTextTitle == null) {
			mTextTitle = (TextView) findViewById(R.id.text_title);
		}

		if (mTextTitle != null) {
			mTextTitle.setText(title);
		}
	}

	public void setTitle(int titleRes, int leftBtnRes,boolean isLeftText, int rightBtnRes,boolean isRightText) {
		setTitle(getString(titleRes), leftBtnRes, isLeftText,rightBtnRes,isRightText);
	}

	public void setTitle(String title, int leftBtnRes, boolean isLeftText,int rightBtnRes,boolean isRightText) {
		setTitle(title);

		ImageButton btnLeft = (ImageButton) findViewById(R.id.btn_header_left);
		ImageButton btnRight = (ImageButton) findViewById(R.id.btn_header_right);
		TextView mHeaderLeftText = (TextView) findViewById(R.id.tv_header_left);
		TextView mHeaderRightText = (TextView) findViewById(R.id.tv_header_right);
		if (leftBtnRes != 0) {
			if(isLeftText){
				mHeaderLeftText.setText(getString(leftBtnRes));
				btnLeft.setVisibility(View.GONE);
				mHeaderLeftText.setVisibility(View.VISIBLE);
			}else{
				btnLeft.setImageResource(leftBtnRes);
				mHeaderLeftText.setVisibility(View.GONE);
				btnLeft.setVisibility(View.VISIBLE);
			}
		} else {
			btnLeft.setVisibility(View.GONE);
			mHeaderLeftText.setVisibility(View.GONE);
		}

		if (rightBtnRes != 0) {
			if(isRightText){
				mHeaderRightText.setText(getString(rightBtnRes));
				btnRight.setVisibility(View.GONE);
				mHeaderRightText.setVisibility(View.VISIBLE);
			}else{
				btnRight.setImageResource(rightBtnRes);
				mHeaderRightText.setVisibility(View.GONE);
				btnRight.setVisibility(View.VISIBLE);
			}
		} else {
			btnRight.setVisibility(View.GONE);
		}
	}
	
	/**
	 * Header 左边按钮点击事件
	 * 
	 * @param view
	 */
	public void onBtnLeft(View view) {
		finish();
	}
	
	/**
	 * Header 左边TextView 的点击事件
	 */
	public void onLeftText(View view){
		finish();
	}

	/**
	 * Header 右边按钮点击事件
	 * 
	 * @param view
	 */
	public void onBtnRight(View view) {
	}

	/**
	 * Header 左边TextView 的点击事件
	 */
	public void onRightText(View view){
	}
	
	public Activity getActivity() {
		return BaseActivity.this;
	}
	
	
}
